package com.ruoyi.notes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.notes.domain.MyNote;
import com.ruoyi.notes.service.IMyNoteService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 	个人笔记Controller
 * 
 * @author ruoyi
 * @date 2022-09-20
 */
@RestController
@RequestMapping("/system/note")
public class MyNoteController extends BaseController {
	@Autowired
	private IMyNoteService myNoteService;

	/**
	 * 	查询个人笔记列表
	 */
	@PreAuthorize("@ss.hasPermi('system:note:list')")
	@GetMapping("/list")
	public TableDataInfo list(MyNote myNote) {
		startPage();
		List<MyNote> list = myNoteService.selectMyNoteList(myNote);
		return getDataTable(list);
	}

	/**
	 * 	导出个人笔记列表
	 */
	@PreAuthorize("@ss.hasPermi('system:note:export')")
	@Log(title = "个人笔记", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, MyNote myNote) {
		List<MyNote> list = myNoteService.selectMyNoteList(myNote);
		ExcelUtil<MyNote> util = new ExcelUtil<MyNote>(MyNote.class);
		util.exportExcel(response, list, "个人笔记数据");
	}

	/**
	 * 	获取个人笔记详细信息
	 */
	@PreAuthorize("@ss.hasPermi('system:note:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(myNoteService.selectMyNoteById(id));
	}

	/**
	 * 	新增个人笔记
	 */
	@PreAuthorize("@ss.hasPermi('system:note:add')")
	@Log(title = "个人笔记", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody MyNote myNote) {
		return toAjax(myNoteService.insertMyNote(myNote));
	}

	/**
	 * 	修改个人笔记
	 */
	@PreAuthorize("@ss.hasPermi('system:note:edit')")
	@Log(title = "个人笔记", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody MyNote myNote) {
		return toAjax(myNoteService.updateMyNote(myNote));
	}

	/**
	 * 	删除个人笔记
	 */
	@PreAuthorize("@ss.hasPermi('system:note:remove')")
	@Log(title = "个人笔记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(myNoteService.deleteMyNoteByIds(ids));
	}
}
